home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr47 / asmlib40.zip / EMSXMS.DOC < prev    next >
Text File  |  1993-04-27  |  32KB  |  1,003 lines

  1.  
  2. ******************** EXPANDED AND EXTENDED MEMORY **************************
  3.  
  4. ASMLIB's EMS subroutines detect and manipulate Expanded Memory hardware
  5. and software.  Expanded memory, when installed in any PC, can help solve
  6. many memory limitation problems.  Call IsEMS before using any other
  7. ASMLIB EMS subroutines.  All ASMLIB EMS subroutines assume DS:@data.
  8.  
  9. EMS memory is allocated in blocks of 16k increments
  10.  
  11. Error codes returned by EMS functions are:
  12.  
  13.    AH = 0      no error
  14.    AH = 80h    error in memory manager software
  15.    AH = 81h    error in expanded memory hardware
  16.    AH = 84h    bad function code passed to memory manager
  17.    AH = 85h    no EMM handles available
  18.    AH = 89h    you tried to allocate zero pages
  19.  
  20.  
  21. ASMLIB also supports XMS-compatible extended memory.  You must call IsXMS
  22. to determine if XMS memory is available before using any ASMLIB XMS
  23. subroutines.  All ASMLIB XMS subroutines assume DS:@data.
  24.  
  25. XMS memory is available on many 286 or better computers with a suitable
  26. driver.  On 286 computers, XMS memory will be much slower than EMS memory.
  27. XMS memory is not available on XT (or compatible) computers.
  28.  
  29. XMS memory is allocated in 1k increments
  30.  
  31. XMS error codes include:
  32.  
  33.    AH = 0                 no error
  34.    AH = 0A0h              all extended memory is allocated
  35.    AH = 0A1h              no handles available
  36.    AH = 0A2h, 0A3h, 0A5h  handle is invalid
  37.    AH = 0A4h, 0A6h        offset is invalid
  38.    AH = 0A7h              length is invalid
  39.  
  40.  
  41. ASMLIB includes disk-based Virtual Memory subroutines (VMS) which make
  42. possible the use of disk space as though it were RAM.  Error codes returned
  43. by VMS subroutines are DOS error codes.
  44.  
  45. ASMLIB's EMS, VMS and XMS subroutines were written with identical calling
  46. parameters and identical returned information for comparable subroutines.
  47. For example, AllocEMS and AllocXMS are both called with DX:AX = the number
  48. of bytes requested.
  49.  
  50.  
  51. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  52.  
  53. ALLOCEMS:   allocates EMS memory
  54. Source:     ems.asm
  55.  
  56. Call with:  DX:AX = number of bytes of memory to allocate
  57.  
  58.             EMS memory is allocated in 16k blocks.  AllocEMS will allocate
  59.             multiple blocks if nessesary.
  60.             NOTE: You must first use IsEMS to determine if Expanded
  61.             memory is installed.
  62.  
  63. Returns:    if CF = 0, BX = EMS handle
  64.             if CF = 1, AH = EMS error code
  65. Uses:       AX, BX, flags
  66. Example:    see example code at the end of this file
  67.  
  68.  
  69.  
  70. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  71.  
  72. ALLOCVMS:   allocates VMS memory
  73. Source:     allocvms.asm
  74.  
  75. Call with:  DX:AX = bytes of VMS memory to allocate
  76.             DS:[SI] pointing to filename for VMS block
  77.             AllocVMS creates a file of the size requested, thus reserving
  78.             space on the disk for the memory block.  The file should not
  79.             be presumed to contain useful data.
  80. Returns:    if CF = 0, BX = VMS handle
  81.             if CF = 1, AX = DOS error code
  82. Uses:       AX, BX, flags
  83. Example:    see example code at the end of this file
  84.  
  85.  
  86.  
  87. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  88.  
  89. ALLOCXMS:   allocates XMS memory
  90. Source:     xms.asm
  91.  
  92. Call with:  DX:AX = number of bytes of memory to allocate
  93.  
  94.             XMS memory is allocated in 1k blocks.  AllocXMS will allocate
  95.             multiple blocks if nessesary.
  96.             NOTE: You must first use IsXMS to determine if XMS Extended
  97.             memory is available.
  98.  
  99. Returns:    if CF = 0, BX = XMS handle
  100.             if CF = 1, AH = XMS error code
  101. Uses:       AX, BX, flags
  102. Example:    see example code at the end of this file
  103.  
  104.  
  105. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  106.  
  107. EMGET:      copy data from EMS memory to system RAM
  108. Source:     emputget.asm ($emspage.asm)
  109.  
  110. Call with:  BX = EMS handle
  111.             ES:[DI] pointing to destination buffer
  112.             DS:[SI] pointing to 4-byte offset in EMS block
  113.             DX:AX = number of bytes to copy
  114. Returns:    if CF = 0, no error
  115.             if CF = 1, AH = EMS error code
  116. Uses:       AX, flags
  117. Example:    see example code at the end of this file
  118.  
  119.  
  120.  
  121. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  122.  
  123. EMMOVE:     move data within an EMS memory block
  124.             this is used most often to make room for additional data
  125.             at a specified location in the EMS block, or to delete data
  126.             from the block.
  127. Source:     emmove.asm (xget$.asm, $xmove.asm, emputget.asm, $emspage.asm)
  128.  
  129. Call with:  BX = valid EMS handle
  130.             DS:[SI] pointing to source offset in EMS block
  131.             DS:[DI] pointing to destination offset in EMS block
  132.             DX:AX = number of bytes to move
  133.  
  134.             64k DOS memory must be available; assumes DS:@data
  135.             EMMove works properly if the source and destination
  136.             overlap; you must make sure the EMS block is large enough
  137.             to accomodate the move.
  138.  
  139. Returns:    if CF = 0, no error
  140.             if CF = 1, AH = DOS or EMS error code
  141.                the only DOS error code likely is 08h, insufficient memory
  142.  
  143. Uses:       AX, flags
  144. Example:
  145.  
  146. ; calculate bytes to move
  147.         mov     ax,block_size
  148.         mov     dx,block_size   ; DX:AX = bytes in expanded memory block
  149.         sub     ax,source
  150.         sbb     dx,source+2     ; DX:AX = bytes in tail end of block
  151.                                 ;       = bytes to move
  152.         mov     bx,block_handle
  153.         lea     si,source
  154.         lea     di,destination
  155.         call    emmove
  156.  
  157.  
  158.  
  159. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  160.  
  161. EMMVER:     determines Expanded Memory Manager version
  162. Source:     emmver.asm
  163.  
  164. Call with:  no parameters
  165. Returns:    if CF = 1, AH = EMS error code
  166.             if CF = 0, AH = major version number
  167.                        AL = minor version number
  168. Uses:       AX, flags
  169. Example:
  170.  
  171. include  asm.inc
  172.  
  173. extrn    isems:proc, emmver:proc
  174.  
  175. .code
  176.          .
  177.          .
  178.          .
  179.          call   isems
  180.          jc     no_ems
  181.          call   emmver     ; get emm version
  182.          jc     ems_error
  183.          cmp    ah,4       ; version 4.x?
  184.          jb     version3x  ; nope, an older EMM version
  185.  
  186.  
  187.  
  188. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  189.  
  190. EMPUT:      copy data to EMS memory from system RAM
  191. Source:     emputget.asm ($emspage.asm)
  192.  
  193. Call with:  BX = EMS handle
  194.             ES:[DI] pointing to data to copy
  195.             DS:[SI] pointing to 4-byte offset in EMS block
  196.             DX:AX = number of bytes to copy
  197. Returns:    if CF = 0, no error
  198.             if CF = 1, AH = EMS error code
  199. Uses:       AX, flags
  200. Example:    see example code at the end of this file
  201.  
  202.  
  203.  
  204. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  205.  
  206. EMSFREE:    determine free EMS memory
  207. Source:     emsfree.asm
  208.  
  209. Call with:  no parameters
  210.  
  211.             EMSFree does not verify that EMS memory is installed; you should
  212.             call IsEMS to determine if EMS memory is installed before using
  213.             this subroutine.  Do not confuse this subroutine with FreeEMS,
  214.             which releases a previously allocated EMS block and handle.
  215.  
  216. Returns:    DX:AX = bytes of EMS memory available
  217. Uses:       AX, DX, flags
  218. Example:
  219.  
  220. include asm.inc
  221.  
  222. public  myprog
  223. extrn   isems:proc, emsfree:proc
  224.  
  225. .code
  226. myprog  proc
  227.         call    isems           ; see if EMS memory is installed
  228.         jc      nope
  229.         call    emsfree         ; is enough available?
  230.         .
  231.         .
  232.         .
  233.  
  234.  
  235.  
  236. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  237.  
  238. EMSTOTAL:   determine total EMS memory installed
  239. Source:     emsfree.asm
  240.  
  241. Call with:  no parameters; call IsEMS to determine if EMS memory is
  242.             installed before using this subroutine
  243. Returns:    DX:AX = bytes of EMS memory installed
  244. Uses:       AX, DX, flags
  245. Example:
  246.  
  247. include asm.inc
  248.  
  249. public  myprog
  250. extrn   isems:proc, emstotal:proc
  251.  
  252. .code
  253. myprog  proc
  254.         call    isems           ; see if EMS memory is installed
  255.         jc      nope
  256.         call    emstotal        ; how much?
  257.         .
  258.         .
  259.         .
  260.  
  261.  
  262. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  263.  
  264. EMISTR:     search expanded memory block for ASCIIZ string, case-insensitive
  265. Source:     emistr.asm (xget$.asm, $xistr.asm, emputget.asm, strlen.asm,
  266.                         $strstr.asm, strlwr.asm)
  267.  
  268. EMSTR:      search expanded memory block for ASCIIZ string, case-sensitive
  269. Source:     emstr.asm (xget$.asm, $xstr.asm, emputget.asm, $strstr.asm,
  270.                        strlen.asm)
  271.  
  272. Call with:  DS:[SI] pointing to ASCIIZ string
  273.             BX = valid EMS handle
  274.             DS:[DI] pointing to 4-byte initial offset for start of search
  275.             DX:AX = number of bytes of EMS block to search
  276.             requires 64k free DOS memory (see ENDPROG and STARTUP.ASM)
  277.  
  278. Returns:    if CF = 0, DX:AX = offset of matching string in EMS block
  279.             if CF = 1:
  280.                if AX = 0, string not found
  281.                 else AH = EMS error code
  282. Uses:       DX,AX, flags
  283.  
  284. Example:
  285.  
  286. include asm.inc
  287.  
  288. public  mycode
  289. extrn   emstr:proc
  290.  
  291. .data
  292. extrn   ems_handle:word
  293. extrn   ems_bytes:word          ; 2 words
  294. ems_offset      dw 0,0          ; start at beginnig of block
  295. search_string   db 'ASMLIB',0
  296.  
  297. .code
  298. mycode  proc
  299. ; program fragment assumes EMS memory has been allocated
  300. ; and has useful data
  301.  
  302.         .
  303.         .
  304.         lea     si,search_string
  305.         mov     bx,ems_handle
  306.         mov     ax,ems_bytes
  307.         mov     dx,ems_bytes+2  ; DX:AX = bytes to search
  308.         lea     di,ems_offset   ; start search at beginning of XMS block
  309.         call    emstr           ; returns DX:AX = offset of 'ASMLIB'
  310.         jnc     found_it
  311.         or      ax,ax
  312.         jz      no_match        ; no errors, but no match either
  313.         jmp     oh_no_an_error  ; jump to error handling code
  314.  
  315.  
  316.  
  317. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  318.  
  319. FLOADEMS:   reads a disk file and copies to EMS memory
  320. Source:     floadems.asm (fsize.asm, ems.asm)
  321.  
  322. Call with:  DS:[DX] pointing to ASCIIZ filename
  323.             call IsEMS before calling FLoadEMS to determine if EMS memory
  324.             is available
  325. Returns:    if CF = 0, BX = EMS handle and DX:AX = bytes copied to EMS
  326.             if CF = 1, AH = EMS error code or AL = DOS error code
  327. Uses:       AX, BX, DX, CF
  328. Example:
  329.  
  330. include asm.inc
  331.  
  332. public  test_ems
  333.  
  334. extrn   isems:proc
  335. extrn   gsave:proc, floadems:proc
  336.  
  337. .data
  338. handle  dw 0
  339. fname   db 'filename.12h',0
  340.  
  341. .code
  342. test_ems        proc
  343. ; program fragment assumes DS:@data
  344.         mov     ax,12h          ; VGA 16-color mode
  345.         int     10h             ; set mode
  346.         .                       ; program draws screen
  347.         .
  348.  
  349. ; I want to save this screen as a disk file
  350.      call isems
  351.      jc   no_good
  352.      lea  dx,fname
  353.      call gsave           ; GSave is in GRAPHICS.DOC
  354.      jc   no_good
  355.         .
  356.         .
  357.  
  358. ; now I want to get back the screen I saved
  359.         lea     dx,fname
  360.         call    floadems        ; read file, load into EMS memory
  361.         mov     handle,bx
  362.         jc      no_good
  363.         call    gloadems        ; copy from EMS memory to video buffer
  364.         jc      kill_ems
  365.         call    getkey          ; now look at the pretty picture
  366. kill_ems:
  367.         mov     dx,handle
  368.         mov     ah,45h
  369.         int     67h
  370.  
  371. no_good:call    modecolor       ; go back to color text mode
  372.         ret
  373. test_ems        endp
  374.         end
  375.  
  376. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  377.  
  378. FLOADVMS:   reads a disk file and copies to VMS memory
  379. Source:     floadvms.asm (fcopy.asm, fsize.asm)
  380.  
  381. Call with:  DS:[DX] pointing to input ASCIIZ filename
  382.             DS:[SI] pointing to VMS filename
  383.              The VMS filename is the name of the file created as VMS memory
  384.              64k DOS memory must be available for FLoadVMS' use
  385.  
  386. Returns:    if CF = 0, BX = VMS handle and DX:AX = bytes copied
  387.             if CF = 1, AX = DOS error code
  388. Uses:       AX, BX, DX, flags
  389. Example:    see FLoadEMS example
  390.  
  391.  
  392.  
  393. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  394.  
  395. FLOADXMS:   reads a disk file and copies to XMS memory
  396. Source:     floadxms.asm (fsize.asm, xmputget.asm, xms.asm)
  397.  
  398. Call with:  DS:[DX] pointing to ASCIIZ filename
  399.             call IsXMS before calling FLoadXMS to determine if XMS memory
  400.             is available
  401.  
  402.             64k DOS memory must be available for FLoadXMS' use
  403.  
  404. Returns:    if CF = 0, BX = XMS handle and DX:AX = bytes copied to XMS
  405.             if CF = 1, AH = XMS error code or AL = DOS error code
  406. Uses:       AX, BX, DX, CF
  407. Example:    see FLoadEMS example
  408.  
  409.  
  410. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  411.  
  412. FSAVEEMS:   writes an EMS memory block to disk file
  413. Source:     fsaveems.asm ($fsavex.asm, emputget.asm)
  414.  
  415. Call with:  DS:[SI] pointing to ASCIIZ filename
  416.             BX = valid EMS handle
  417.             DX:AX = bytes to write
  418.  
  419.             64k DOS memory must be available for FSaveEMS' use
  420.  
  421. Returns:    if CF = 0, no error
  422.             if CF = 1, AH = EMS error code or AL = DOS error code
  423. Uses:       AX, flags
  424. Example:
  425.  
  426. .data
  427. emsfile        db 'bigblock.ems',0
  428. emssize        dd ?                  ; program fills in the numbers
  429. emshandle      dw ?                  ; program fills in the numbers
  430.  
  431. .code
  432. swap_ems_to_disk   proc
  433. ; program fragment assumes DS:@data
  434.        lea     si,emsfile            ; filename
  435.        mov     bx,emshandle
  436.        mov     ax,word ptr emssize
  437.        mov     dx,word ptr emssize+2 ; DX:AX = bytes to save
  438.        call    fsaveems              ; save EMS block as disk file
  439.        jc      no_good
  440.  
  441.  
  442.  
  443. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  444.  
  445. FSAVEVMS:   save a VMS memory block as a disk file
  446. Source:     fsavevms.asm (xget$.asm, $fsavex.asm, vmputget.asm)
  447.  
  448. Call with:  DS:[SI] pointing to ASCIIZ filename
  449.             BX = valid VMS handle
  450.             DX:AX = bytes to write
  451.  
  452.             64k DOS memory must be available for FSaveVMS' use
  453.  
  454. Returns:    if CF = 0, no error
  455.             if CF = 1, AX = DOS error code
  456. Uses:       AX, flags
  457. Example:    see FSaveEMS example
  458.  
  459.  
  460.  
  461. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  462.  
  463. FSAVEXMS:   writes an XMS memory block to disk file
  464. Source:     fsavexms.asm (xget$.asm, $fsavex.asm, xms.asm, xmputget.asm)
  465.  
  466. Call with:  DS:[SI] pointing to ASCIIZ filename
  467.             BX = valid XMS handle
  468.             DX:AX = bytes to write
  469.  
  470.             64k DOS memory must be available for FSaveXMS' use
  471.  
  472. Returns:    if CF = 0, no error
  473.             if CF = 1, AH = XMS error code or AL = DOS error code
  474. Uses:       AX, flags
  475. Example:    see FSaveEMS example
  476.  
  477.  
  478.  
  479. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  480.  
  481. FREEEMS:    releases an EMS memory block and handle
  482. Source:     ems.asm
  483.  
  484. Call with:  BX = EMS handle
  485.  
  486.             NOTE: DOS does not release EMS memory when your program
  487.             returns to DOS.  Your program must close any open EMS handles
  488.             before quitting, or the EMS memory associated with the handles
  489.             will be unavailable to other programs.  Do not confuse this
  490.             subroutine with EMSFree, whick determines the EMS memory
  491.             available.
  492.  
  493. Returns:    if CF = 0, no error
  494.             if CF = 1, AH = EMS error code
  495. Uses:       AX, flags
  496. Example:    see example code at the end of this file
  497.  
  498.  
  499.  
  500. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  501.  
  502. FREEVMS:    releases a VMS memory block and handle
  503. Source:     freevms.asm
  504.  
  505. Call with:  BX = VMS handle
  506.             DS:[SI] pointing to VMS block filename
  507.  
  508. Returns:    if CF = 0, no error
  509.             if CF = 1, AX = DOS error code
  510. Uses:       AX, flags
  511. Example:    see example code at the end of this file
  512.  
  513.  
  514.  
  515. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  516.  
  517. FREEXMS:    releases an XMS memory block and handle
  518. Source:     xms.asm
  519.  
  520. Call with:  BX = XMS handle
  521.  
  522.             NOTE: DOS does not release XMS memory when your program ends.
  523.             Your program must close any open XMS handles before quitting,
  524.             or the XMS memory associated with the handles will be
  525.             unavailable to other programs.  Do not confuse this subroutine
  526.             with XMSFree, whick determines the XMS memory available.
  527.  
  528. Returns:    if CF = 0, no error
  529.             if CF = 1, AH = XMS error code
  530. Uses:       AX, flags
  531. Example:    see example code at the end of this file
  532.  
  533.  
  534.  
  535. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  536.  
  537. ISEMS:      detects EMS driver
  538. Source:     isems.asm
  539.  
  540. Call with:  no parameters
  541. Returns:    if CF = 1, no Expanded Memory manager installed
  542.             if CF = 0, EMS memory is installed
  543. Uses:       CF
  544. Example:    see example code at the end of this file
  545.  
  546.  
  547.  
  548.  
  549. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  550.  
  551. ISXMS:      detects XMS driver
  552. Source:     isxms.asm
  553. Call with:  no parameters
  554. Returns:    if CF = 1, no XMS driver is installed
  555.             if CF = 0, XMS memory is available
  556. Uses:       CF
  557. Example:    see example code at the end of this file
  558.  
  559.  
  560.  
  561. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  562.  
  563. REALLOCEMS: re-size a previously allocated EMS memory block
  564. Source:     realloce.asm
  565.  
  566. Call with:  BX = valid EMS memory handle
  567.             DX:AX = requested bytes
  568. Returns:    if CF = 0, no error
  569.             if CF = 1, AH = EMS error code
  570. Supports:   EMS version 4.0 or greater (see EMMVER)
  571. Uses:       AX, flags
  572. Example:
  573.  
  574.         mov   bx,emshandle           ; existing valid EMS handle
  575.         mov   ax,bytes
  576.         mov   dx,bytes+2             ; DX:AX = bytes requested
  577.         call  reallocems             ; try to re-size existing block
  578.         jc    alloc_error
  579.  
  580.  
  581. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  582.  
  583. REALLOCVMS: re-size a previously allocated VMS memory block
  584. Source:     reallocv.asm
  585.  
  586. Call with:  BX = valid VMS memory handle
  587.             DX:AX = requested bytes
  588.  
  589.             Note that ReallocVMS can only make the VMS block larger
  590.             if a smaller VMS block is requested, ReallocVMS does nothing
  591.             and returns with CF = 0
  592.  
  593. Returns:    if CF = 0, no error
  594.             if CF = 1, AX = DOS error code
  595. Uses:       AX, flags
  596. Example:
  597.  
  598.         mov   bx,vmshandle           ; existing valid VMS handle
  599.         mov   ax,bytes
  600.         mov   dx,bytes+2             ; DX:AX = bytes requested
  601.         call  reallocvms             ; try to re-size existing block
  602.         jc    alloc_error
  603.  
  604.  
  605. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  606.  
  607. REALLOCXMS: re-size a previously allocated XMS memory block
  608. Source:     reallocx.asm (xms.asm)
  609.  
  610. Call with:  BX = valid XMS memory handle
  611.             DX:AX = requested bytes
  612. Returns:    if CF = 0, no error
  613.             if CF = 1, AH = XMS error code
  614. Uses:       AX, flags
  615. Example:
  616.  
  617.         mov   bx,xmshandle           ; existing valid XMS handle
  618.         mov   ax,bytes
  619.         mov   dx,bytes+2             ; DX:AX = bytes requested
  620.         call  reallocxms             ; try to re-size existing block
  621.         jc    alloc_error
  622.  
  623.  
  624. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  625.  
  626. VMGET:      copy data from VMS memory to system RAM
  627. Source:     vmputget.asm
  628.  
  629. Call with:  BX = VMS handle
  630.             ES:[DI] pointing to destination buffer
  631.             DS:[SI] pointing to 4-byte offset in VMS block
  632.             DX:AX = number of bytes to copy
  633. Returns:    if CF = 0, no error
  634.             if CF = 1, AX = DOS error code
  635. Uses:       AX, flags
  636. Example:    see example code at the end of this file
  637.  
  638.  
  639.  
  640. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  641.  
  642. VMMOVE:     move data within a VMS memory block
  643. Source:     vmmove.asm (xget$.asm, $xmove.asm, vmputget.asm)
  644.  
  645. Call with:  BX = valid VMS handle
  646.             DS:[SI] pointing to source offset in VMS block
  647.             DS:[DI] pointing to destination offset in VMS block
  648.             DX:AX = number of bytes to move
  649.  
  650.             64k DOS memory must be available; assumes DS:@data
  651.             VMMove works properly if the source and destination
  652.             overlap; you must make sure the block is large enough
  653.             to accomodate the move.
  654.  
  655. Returns:    if CF = 0, no error
  656.             if CF = 1, AX = DOS error code
  657.  
  658. Uses:       AX, flags
  659. Example:
  660.  
  661. ; calculate bytes to move
  662.         mov     ax,block_size
  663.         mov     dx,block_size   ; DX:AX = bytes in extended memory block
  664.         sub     ax,source
  665.         sbb     dx,source+2     ; DX:AX = bytes in tail end of block
  666.                                 ;       = bytes to move
  667.         mov     bx,block_handle
  668.         lea     si,source
  669.         lea     di,destination
  670.         call    vmmove
  671.  
  672.  
  673. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  674.  
  675. VMPUT:      copy data to VMS memory from system RAM
  676. Source:     vmputget.asm
  677.  
  678. Call with:  BX = VMS handle
  679.             ES:[DI] pointing to data to copy
  680.             DS:[SI] pointing to 4-byte offset in VMS block
  681.             DX:AX = number of bytes to copy
  682. Returns:    if CF = 0, no error
  683.             if CF = 1, AX = VMS error code
  684. Uses:       AX, flags
  685. Example:    see example code at the end of this file
  686.  
  687.  
  688.  
  689.  
  690. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  691.  
  692. VMISTR:     search VMS memory block for ASCIIZ string, case-insensitive
  693. Source:     vmistr.asm (xget$.asm, $xistr.asm, vmputget.asm, strlen.asm,
  694.                         strlwr.asm)
  695.  
  696. VMSTR:      search VMS memory block for ASCIIZ string, case-sensitive
  697. Source:     vmstr.asm (xget$.asm, $xstr.asm, vmputget.asm, strlen.asm)
  698.  
  699. Call with:  DS:[SI] pointing to ASCIIZ string
  700.             BX = valid VMS handle
  701.             DS:[DI] pointing to 4-byte initial offset for start of search
  702.             DX:AX = number of bytes of VMS block to search
  703.             requires 64k free DOS memory (see ENDPROG and STARTUP.ASM)
  704.  
  705. Returns:    if CF = 0, DX:AX = offset of matching string in VMS block
  706.             if CF = 1:
  707.                if AX = 0, string not found
  708.                 else AX = DOS error code
  709. Uses:       DX, AX, flags
  710.  
  711. Example:
  712.  
  713. include asm.inc
  714.  
  715. public  mycode
  716. extrn   vmstr:proc
  717.  
  718. .data
  719. extrn   vms_handle:word
  720. extrn   vms_bytes:word          ; 2 words
  721. vms_offset      dw 0,0          ; start at beginnig of block
  722. search_string   db 'ASMLIB',0
  723.  
  724. .code
  725. mycode  proc
  726. ; program fragment assumes VMS memory has been allocated
  727. ; and has useful data
  728.  
  729.         .
  730.         .
  731.         lea     si,search_string
  732.         mov     bx,vms_handle
  733.         mov     ax,vms_bytes
  734.         mov     dx,vms_bytes+2  ; DX:AX = bytes to search
  735.         lea     di,vms_offset   ; start search at beginning of VMS block
  736.         call    vmstr           ; returns DX:AX = offset of 'ASMLIB'
  737.         jnc     found_it
  738.         or      ax,ax
  739.         jz      no_match        ; no errors, but no match either
  740.         jmp     oh_no_an_error  ; jump to error handling code
  741.  
  742.  
  743.  
  744. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  745.  
  746. XMGET:      copy data from XMS memory to system RAM
  747. Source:     xmputget.asm (xms.asm)
  748.  
  749. Call with:  BX = XMS handle
  750.             ES:[DI] pointing to destination buffer
  751.             DS:[SI] pointing to 4-byte offset in XMS block
  752.             DX:AX = number of bytes to copy (minimum 2 bytes)
  753. Returns:    if CF = 0, no error
  754.             if CF = 1, AH = XMS error code
  755. Uses:       AX, flags
  756. Example:    see example code at the end of this file
  757.  
  758.  
  759.  
  760. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  761.  
  762. XMMOVE:     move data within an XMS memory block
  763. Source:     xmmove.asm (xget$.asm, $xmove.asm, xmputget.asm, xms.asm)
  764.  
  765. Call with:  BX = valid XMS handle
  766.             DS:[SI] pointing to source offset in XMS block
  767.             DS:[DI] pointing to destination offset in XMS block
  768.             DX:AX = number of bytes to move (minimum 2 bytes)
  769.  
  770.             64k DOS memory must be available; assumes DS:@data
  771.             XMMove works properly if the source and destination
  772.             overlap; you must make sure the block is large enough
  773.             to accomodate the move.
  774.  
  775. Returns:    if CF = 0, no error
  776.             if CF = 1, AH = DOS or XMS error code
  777.                the only DOS error code likely is 08h, insufficient memory
  778.  
  779. Uses:       AX, flags
  780. Example:
  781.  
  782. ; calculate bytes to move
  783.         mov     ax,block_size
  784.         mov     dx,block_size   ; DX:AX = bytes in extended memory block
  785.         sub     ax,source
  786.         sbb     dx,source+2     ; DX:AX = bytes in tail end of block
  787.                                 ;       = bytes to move
  788.         mov     bx,block_handle
  789.         lea     si,source
  790.         lea     di,destination
  791.         call    xmmove
  792.  
  793.  
  794.  
  795. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  796.  
  797. XMPUT:      copy data to XMS memory from system RAM
  798. Source:     xmputget.asm (xms.asm)
  799.  
  800. Call with:  BX = XMS handle
  801.             ES:[DI] pointing to data to copy
  802.             DS:[SI] pointing to 4-byte offset in XMS block
  803.             DX:AX = number of bytes to copy (minimum 2 bytes)
  804. Returns:    if CF = 0, no error
  805.             if CF = 1, AH = XMS error code
  806. Uses:       AX, flags
  807. Example:    see example code at the end of this file
  808.  
  809.  
  810.  
  811.  
  812. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  813.  
  814. XMSFREE:    determine free XMS memory
  815. Source:     xmsfree.asm
  816.  
  817. Call with:  no parameters
  818.  
  819.             XMSFree does not verify that XMS memory is installed; you should
  820.             call IsXMS to determine if XMS memory is installed before using
  821.             this subroutine.  Do not confuse this subroutine with FreeXMS,
  822.             which releases a previously allocated XMS block and handle.
  823.  
  824. Returns:    DX:AX = bytes of XMS memory available
  825. Uses:       AX, DX, flags
  826. Example:
  827.  
  828. include asm.inc
  829.  
  830. public  myprog
  831. extrn   isxms:proc, xmsfree:proc
  832.  
  833. .code
  834. myprog  proc
  835.         call    isxms           ; see if XMS memory is installed
  836.         jc      nope
  837.         call    xmsfree         ; is enough available?
  838.         .
  839.         .
  840.         .
  841.  
  842.  
  843.  
  844. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  845.  
  846. XMISTR:     search extended memory block for ASCIIZ string, case-insensitive
  847. Source:     xmistr.asm (xget$.asm, $xistr.asm, xmputget.asm, strlen.asm,
  848.                         strlwr.asm)
  849.  
  850. XMSTR:      search extended memory block for ASCIIZ string, case-sensitive
  851. Source:     xmstr.asm (xget$.asm, $xstr.asm, xmputget.asm, strlen.asm)
  852.  
  853. Call with:  DS:[SI] pointing to ASCIIZ string
  854.             BX = valid XMS handle
  855.             DS:[DI] pointing to 4-byte initial offset for start of search
  856.             DX:AX = number of bytes of XMS block to search
  857.             requires 64k free DOS memory (see ENDPROG and STARTUP.ASM)
  858.  
  859. Returns:    if CF = 0, DX:AX = offset of matching string in XMS block
  860.             if CF = 1:
  861.                if AX = 0, string not found
  862.                 else AH = XMS error code
  863. Uses:       DX,AX, flags
  864.  
  865. Example:
  866.  
  867. include asm.inc
  868.  
  869. public  mycode
  870. extrn   xmstr:proc
  871.  
  872. .data
  873. extrn   xms_handle:word
  874. extrn   xms_bytes:word          ; 2 words
  875. xms_offset      dw 0,0          ; start at beginnig of block
  876. search_string   db 'ASMLIB',0
  877.  
  878. .code
  879. mycode  proc
  880. ; program fragment assumes XMS memory has been allocated
  881. ; and has useful data
  882.  
  883.         .
  884.         .
  885.         lea     si,search_string
  886.         mov     bx,xms_handle
  887.         mov     ax,xms_bytes
  888.         mov     dx,xms_bytes+2  ; DX:AX = bytes to search
  889.         lea     di,xms_offset   ; start search at beginning of XMS block
  890.         call    xmstr           ; returns DX:AX = offset of 'ASMLIB'
  891.         jnc     found_it
  892.         or      ax,ax
  893.         jz      no_match        ; no errors, but no match either
  894.         jmp     oh_no_an_error  ; jump to error handling code
  895.  
  896.  
  897.  
  898.  
  899.  
  900. ; EXPANDED AND EXTENDED MEMORY EXAMPLE CODE
  901.  
  902. ; This example determines if EMS or XMS memory is installed, allocates
  903. ; 32k of EMS or XMS memory, copies a Herules graph to the allocated memory
  904. ; and later, copies the data back to the video buffer and releases
  905. ; the memory block
  906.  
  907. include asm.inc
  908.  
  909. public  herc2x
  910.  
  911. extrn   isems:proc, isxms:proc
  912. extrn   allocems:proc, allocxms:proc
  913. extrn   emput:proc, xmput:proc
  914. extrn   emget:proc, xmget:proc
  915. extrn   freeems:proc, freexms:proc
  916.  
  917. .data
  918. IF @codesize
  919. xalloc  dd 0
  920. xput    dd 0
  921. xget    dd 0
  922. xfree   dd 0
  923. ELSE
  924. xalloc  dw 0
  925. xput    dw 0
  926. xget    dw 0
  927. xfree   dw 0
  928. ENDIF
  929. xoffset dw 0,0
  930. xhandle dw 0
  931. xerror  dw 0
  932.  
  933. .code
  934. herc2x  proc
  935. ; program fragment assumes DS:@data
  936. ; set up default conditions: use EMS
  937.         mov     xerror,offset ems_error
  938.         mov     word ptr xalloc,offset allocems
  939.         mov     word ptr xput,offset emput
  940.         mov     word ptr xget,offset emget
  941.         mov     word ptr xfree,offset freeems
  942. IF @codesize
  943.         mov     ax,seg allocems
  944.         mov     word ptr xalloc+2,ax  ; all ASMLIB code in same segment
  945.         mov     word ptr xput+2,ax
  946.         mov     word ptr xget+2,ax
  947.         mov     word ptr xfree+2,ax
  948. ENDIF
  949.  
  950. ; see if EMS is installed
  951.         call    isems
  952.         jnc     allocate_memory
  953.  
  954. ; EMS not installed - see if XMS memory is avaialble
  955. ; set up for XMS subroutines
  956.         mov     xerror,offset xms_error
  957.         mov     word ptr xalloc,offset allocxms
  958.         mov     word ptr xput,offset xmput
  959.         mov     word ptr xget,offset xmget
  960.         mov     word ptr xfree,offset freexms
  961. IF @codesize
  962.         mov     ax,seg allocxms
  963.         mov     word ptr xalloc+2,ax  ; all ASMLIB code in same segment
  964.         mov     word ptr xput+2,ax
  965.         mov     word ptr xget+2,ax
  966.         mov     word ptr xfree+2,ax
  967. ENDIF
  968.         call    isxms
  969.         jc      foiled_again         ; don't use EMS or XMS
  970.  
  971. ; allocate 32k
  972. allocate_memory:
  973.         mov     ax,32768
  974.         xor     dx,dx                ; DX:AX = 32768
  975.         call    xalloc               ; allocate EMS or XMS memory block
  976.         jc      xerror
  977.         mov     xhandle,bx           ; save the handle
  978.  
  979. ; copy the graph to EMS or XMS
  980.         mov     di,0B000h            ; Hercules buffer
  981.         mov     es,di
  982.         xor     di,di                ; ES:[DI] -> video buffer
  983.         mov     ax,32768             ; copy entire graph
  984.         lea     si,xoffset           ; start at offset 0 in memory block
  985.         call    xput                 ; copy the graph to memory
  986.         jc      xerror
  987.  
  988. ; later ...
  989. ; copy the graph back to the video buffer
  990.         mov     bx,xhandle
  991.         mov     dx,0B000h
  992.         mov     es,dx
  993.         xor     di,di                ; ES:[DI] points to destination
  994.         mov     ax,32768             ; copy all 32k
  995.         xor     dx,dx                ; DX:AX = 32768
  996.         lea     si,xoffset           ; start at offset 0 in memory block
  997.         call    xget                 ; copy the graph back to video buffer
  998.         jc      xerror
  999.  
  1000. ; all done with graph copy; release the memory block
  1001.         call    xfree
  1002.         jc      xerror
  1003.